package com.codeduck.async.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-26
 */
@Service
@Slf4j
public class TaskService {

    @Async
    public void asyncTask() {
        try {
            TimeUnit.SECONDS.sleep(2);
            log.info(Thread.currentThread().getName() + " 任务执行完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void syncTask() {
        try {
            TimeUnit.SECONDS.sleep(2);
            log.info(Thread.currentThread().getName() + " 任务执行完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
